package com.slm.report.view.data;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.Nullable;

import com.slm.report.databinding.ViewVisionLayoutBinding;

/**
 * @ProjectName: My Application
 * @Package: com.slm.report.view.data
 * @ClassName: VisionContentView
 * @Description: java类作用描述
 * @Author: 王丹丹
 * @CreateDate: 2020/6/2 11:30
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/6/2 11:30
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class VisionContentView extends BaseContentView {
    private ViewVisionLayoutBinding viewVisionLayoutBinding = null;
    private String leftValue;
    private String rightValue;

    public VisionContentView(Context context) {
        this(context, null);
    }

    public VisionContentView(Context context, @Nullable AttributeSet attrs) {
        super(context,attrs);
        viewVisionLayoutBinding = ViewVisionLayoutBinding.inflate(LayoutInflater.from(getContext()), this, true);
        viewVisionLayoutBinding.lTv.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                leftValue = s.toString();
                contentDataBean.getValueMap().put("left", leftValue);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        viewVisionLayoutBinding.rTv.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                rightValue = s.toString();
                contentDataBean.getValueMap().put("right", rightValue);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }


    @Override
    void upDataContent() {
        viewVisionLayoutBinding.titleTv.setText(contentDataBean.getTitleStr());
        viewVisionLayoutBinding.lTv.setText(contentDataBean.getValueMap().get("left"));
        viewVisionLayoutBinding.rTv.setText(contentDataBean.getValueMap().get("right"));
        if (!isEdit) {
            viewVisionLayoutBinding.rTv.setHint("");
            viewVisionLayoutBinding.lTv.setHint("");
            viewVisionLayoutBinding.lTv.setFocusable(false);
            viewVisionLayoutBinding.lTv.setFocusableInTouchMode(false);
            viewVisionLayoutBinding.rTv.setFocusable(false);
            viewVisionLayoutBinding.rTv.setFocusableInTouchMode(false);
        }
    }
}
